<?php 
// get website title
if(!function_exists("nvr_document_title")){
	function nvr_document_title(){
		/*
		 * Print the <title> tag based on what is being viewed.
		 */
		global $page, $paged;
	
		wp_title( '|', true, 'right' );
		if( !defined('WPSEO_URL') ){
			// Add the blog name.
			bloginfo( 'name' );
		
			// Add the blog description for the home/front page.
			$site_description = get_bloginfo( 'description', 'display' );
			if ( $site_description && ( is_home() || is_front_page() ) )
				echo " | $site_description";
		
			// Add a page number if necessary:
			if ( $paged >= 2 || $page >= 2 )
				echo ' | ' . sprintf( __( 'Page %s', THE_LANG ), max( $paged, $page ) );
		}
	}// end nvr_document_title()
}

// head action hook
if(!function_exists("nvr_head")){
	function nvr_head(){
		do_action("nvr_head");
	}
	add_action('wp_head', 'nvr_head', 20);
}

if(!function_exists("nvr_metaviewport")){
	function nvr_metaviewport(){
		$dis_viewport = nvr_get_option(THE_SHORTNAME . '_disable_viewport');

		if(!$dis_viewport){
			echo '<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />';
		}
	}
	add_action('nvr_head', 'nvr_metaviewport', 5);
}

if(!function_exists("nvr_print_headmiscellaneous")){
	function nvr_print_headmiscellaneous(){
	
		echo "<!--[if lt IE 9]>\n";
		echo "<script src='".THE_JSURI."html5shiv.js type='text/javascript'></script>\n";
		echo "<![endif]-->\n";

        $favicon = nvr_get_option( THE_SHORTNAME . '_favicon');
		
        if(isset($favicon['url']) && $favicon['url']!="" ){
            $faviconurl = $favicon['url'];
        }else{
			$faviconurl = get_template_directory_uri() . '/images/favicon.ico';
		}
		echo '<link rel="shortcut icon" href="' . $faviconurl . '" />';
        
	}
	add_action('nvr_head', 'nvr_print_headmiscellaneous', 6);
}

// print the logo html
if(!function_exists("nvr_logo")){
	function nvr_logo(){ 
		
		$shortname = THE_SHORTNAME;
		$logotype = nvr_get_option( $shortname . '_logo_type');
		$logoimage = nvr_get_option( $shortname . '_logo_image');
		$logoimagedark = nvr_get_option( $shortname . '_logo_image_dark');  
		$sitename =  nvr_get_option( $shortname . '_site_name');
		$tagline = nvr_get_option( $shortname . '_tagline');
		
		if($sitename=="") $sitename = get_bloginfo('name');
		if($tagline=="") $tagline = get_bloginfo('description'); 

		if(isset($logoimage['url']) && $logoimage['url']!=""){
			$logoimageurl = $logoimage['url'];
		}else{
			$logoimageurl = get_stylesheet_directory_uri() . "/images/logo.png"; 
		}
		
		if(isset($logoimagedark['url']) && $logoimagedark['url']!=""){
			$logoimagedarkurl = $logoimagedark['url'];
		}else{
			$logoimagedarkurl = $logoimageurl; 
		}
?>
		<?php if($logotype == 'textlogo'){ ?>
			
			<h1><a href="<?php echo home_url( '/'); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', THE_LANG ) ); ?>"><?php echo $sitename; ?></a></h1><span class="desc"><?php echo $tagline; ?></span>
        
        <?php } else { ?>
        	
            <div class="logoimg">
            <a href="<?php echo home_url( '/' ) ; ?>" title="<?php echo $sitename; ?>" >
                <img src="<?php echo $logoimageurl ; ?>" alt="<?php echo $sitename; ?>" class="lightlogo" />
                <img src="<?php echo $logoimagedarkurl ; ?>" alt="<?php echo $sitename; ?>" class="darklogo" />
            </a>
            </div>
            
		<?php } ?>
        
<?php 
	}
}

if(!function_exists("nvr_searchform")){
	function nvr_searchform($id="", $class=""){
		if(function_exists('is_woocommerce')){
			$outputposttype = '<input type="hidden" name="post_type" value="product" />';
			$searchtext = __('Search product...', THE_LANG );
		}else{
			$outputposttype = '';
			$searchtext = __('Search...', THE_LANG );
		}
		$output = '<div class="'.$class.'">';
			$output .= '<form method="get" id="'.$id.'" class="btntoppanel" action="'. esc_url( home_url( '/' ) ) .'">';
				$output .= '<div class="searcharea">';
					$output .= '<input type="text" name="s" class="txtsearch" placeholder="'. $searchtext .'" value="" />';
					$output .= '<input type="submit" class="submit" name="submit" value="" />';
					$output .= $outputposttype;
				$output .= '</div>';
			$output .= '</form>';
		$output .= '</div>';
		
		return $output;
	}
}

if (!function_exists('nvr_socialicon')){
	function nvr_socialicon(){
		
		$shortname = THE_SHORTNAME;
		$optSocialIcons = nvr_fontsocialicon();
		
		$outputli = "";
		foreach($optSocialIcons as $optSocialIcon => $optSocialText){
			$sociallink = nvr_get_option( $shortname . '_socialicon_'.$optSocialIcon, "" );
			if(isset($sociallink) && $sociallink!=''){
				$outputli .= '<li><a href="'.$sociallink.'" class="fa '.$optSocialIcon.'"></a></li>'."\n";
			}
		}
		$output = "";
		if($outputli!=""){
			$output .= '<ul class="sn">';
			$output .= $outputli;
			$output .= '</ul>';
		}
		return $output;
	}
}//end if(!function_exists('nvr_get_socialicon'))

if (!function_exists('nvr_showavatar')){
	function nvr_showavatar(){
		
		$shortname = THE_SHORTNAME;
		$args = array(
			'role' => 'administrator',
			'orderby' => 'ID'
		);
		$super_admins = get_users($args);
		foreach ($super_admins as $admin) {
		  $superadmin = $admin;
		  break;
		}
		$avatar = $superadmin->ID;
		
		$customavatar = nvr_get_option( $shortname . '_avatar_email', "" );
		
		if($customavatar!=''){
			$avatar = $customavatar;
		}
		
		return get_avatar($avatar, 123);
	}
}//end if(!function_exists('nvr_get_socialicon'))

if(!function_exists('nvr_breadcrumb')){
	function nvr_breadcrumb(){
		if(function_exists('woocommerce_breadcrumb')){
			woocommerce_breadcrumb();
		}elseif(function_exists('yoast_breadcrumb')){
			yoast_breadcrumb('<nav class="nvr-breadcrumb">','</nav><div class="clearfix"></div>');
		}
	}
}

if(!function_exists('nvr_output_socialicon')){
	function nvr_output_socialicon($pretext=''){
		/*=====SOCIALICON======*/
		$socialiconoutput = nvr_socialicon();
		if($socialiconoutput!=''){				
			// get the social network icon
			if($pretext){
				echo '<h6 class="iconpretext">'.$pretext.'</h6>';
			}
			echo '<div class="topicon">'. $socialiconoutput .'</div>';
		}
	}
}

if(!function_exists('nvr_output_searchbox')){
	function nvr_output_searchbox(){
		$shortname = THE_SHORTNAME;
		$disable_topsearch = nvr_get_option($shortname . '_disable_topsearch');
		if($disable_topsearch!='1'){
			echo nvr_searchform("","searchbox"); 
		}
	}
}

if(!function_exists('nvr_output_showavatar')){
	function nvr_output_showavatar(){
		$shortname = THE_SHORTNAME;
		$outputavatar = nvr_showavatar();
		$disableavatar = nvr_get_option( $shortname . '_disable_avatar');
		if($outputavatar && !$disableavatar){
			echo '<div class="avatarcontainer">'.nvr_showavatar().'</div>'; 
		}
	}
}